home *** CD-ROM | disk | FTP | other *** search
/ Night Owl - The Best of BBS / Night Owl The Best of BBS (NOP-BBS) (Night Owl Publisher) (1994).iso / 022a / td183buf.lha / obsolete / td183fix.s < prev   
Text File  |  1994-02-25  |  7KB  |  370 lines

  1. *
  2. * D'ya know that TrapDoor 1.83 gurus if during EMSI connections it
  3. * receives a string longer than 512 bytes?
  4. *
  5. * EMSI strings are stored just below the stack. Now, if a string is too
  6. * long it scratches the program stack making each RTS instruction to
  7. * become a ACPU_(#?)Err bomb (return address is stored on the stack).
  8. *
  9. * The patch is VERY SIMPLE: it increases by 64 times the strings buffer
  10. * (old buffer was 512 bytes long, the new buffer is 32752 bytes long).
  11. * The bug is still there, so do not call nodes with more than 32752
  12. * bytes long AKA string ;-)
  13. *
  14. * Have fun, 
  15. * /\/ / /-<
  16. *
  17. * You can E-Mail me at:
  18. *
  19. * Fidonet.org:    Nicola Soggia (2:331/315.3)
  20. * Amiganet.ftn:   Nicola Soggia (39:101/102.3)
  21. * Internet/Arpa:  Nicola.Soggia@p3.f315.n331.z2.fidonet.org
  22. *
  23.  
  24. *
  25. * A0 = scratch        D0 = scratch
  26. * A1 = scratch        D1 = scratch
  27. * A2 = temp        D2 = dos buffer ptr
  28. * A3 =             D3 = dos buffer lenght
  29. * A4 =             D4 = fhandle
  30. * A5 = buffer ptr    D5 = td 1.83 executable size
  31. * A6 = dos base        D6 = std in
  32. * A7 = stack ptr    D7 = std out
  33. *
  34.  
  35.     INCDIR    "include:"
  36.     INCLUDE    "exec/types.i"
  37.     INCLUDE    "exec/strings.i"
  38.  
  39.     INCLUDE    "exec/exec_lib.i"
  40.     INCLUDE    "libraries/dos_lib.i"
  41.  
  42.     INCLUDE    "libraries/dos.i"
  43.     INCLUDE    "libraries/dosextens.i"
  44.  
  45. NULL    EQU    0
  46.  
  47. TDSIZE    SET    105664
  48. FILEBND    SET    1
  49. BUFSIZE    SET    256
  50. STKSIZE    SET    (32768-BYTESPERLONG)        ; TOO BIG (TRY WITH 2KB)
  51.  
  52. SETMSG    MACRO
  53.     lea    msg\1(pc),a0
  54.     moveq    #(msg\1e-msg\1),d3
  55.     ENDM
  56.  
  57.  
  58. **********************************************************************
  59. **  MINI-EASYSTART  **************************************************
  60. **********************************************************************
  61.  
  62.  
  63.     suba.l    a1,a1                ; = lea #NULL,a1
  64.     movea.l    4.w,a6
  65.     jsr    _LVOFindTask(a6)
  66.     movea.l    d0,a2
  67.  
  68.     tst.l    pr_CLI(a2)
  69.     bne.s    opendos
  70.  
  71.     lea    pr_MsgPort(a2),a0
  72.     jsr    _LVOWaitPort(a6)
  73.     lea    pr_MsgPort(a2),a0
  74.     jsr    _LVOGetMsg(a6)
  75.     movea.l    d0,a1
  76.     jsr    _LVOReplyMsg(a6)
  77.     moveq    #RETURN_OK,d0
  78.     rts
  79.  
  80.  
  81. **********************************************************************
  82. **  REGISTERS SETUP  *************************************************
  83. **********************************************************************
  84.  
  85.  
  86. opendos    lea    buffer,a5
  87.     move.l    #TDSIZE,d5
  88.  
  89.     lea    dosname(pc),a1
  90.     moveq    #33,d0                ; ks 1.2+
  91.     jsr    _LVOOpenLibrary(a6)
  92.     tst.l    d0
  93.     beq    fault
  94.     movea.l    d0,a6
  95.  
  96.     jsr    _LVOInput(a6)
  97.     move.l    d0,d6
  98.     beq    clsdos
  99.     jsr    _LVOOutput(a6)
  100.     move.l    d0,d7
  101.     beq    clsdos
  102.  
  103.  
  104. **********************************************************************
  105. **  GET FILE NAME  ***************************************************
  106. **********************************************************************
  107.  
  108.  
  109.     lea    msginf(pc),a0
  110.     move.l    #(msginfe-msginf),d3
  111.     bsr    stdout
  112.  
  113.     move.l    #BUFSIZE,d3
  114.     move.l    d6,d1
  115.     suba.l    d3,sp
  116.     move.l    sp,d2
  117.     jsr    _LVORead(a6)
  118.     clr.b    0(sp,d0)
  119.     cmpi.b    #LF,-1(sp,d0)
  120.     bne.s    opentd
  121.     clr.b    -1(sp,d0)
  122.  
  123.  
  124. **********************************************************************
  125. **  READ FILE  *******************************************************
  126. **********************************************************************
  127.  
  128.  
  129. opentd    SETMSG    lo3
  130.     moveq    #NULL,d4
  131.     tst.b    (sp)
  132.     beq.s    loading
  133.  
  134.     move.l    sp,d1
  135.     move.l    #MODE_OLDFILE,d2
  136.     jsr    _LVOOpen(a6)
  137.  
  138.     SETMSG    lo1
  139.     move.l    d0,d4
  140.     bne.s    loading
  141.     SETMSG    lo2
  142.  
  143. loading    bsr    stdout
  144.     move.l    d4,d1
  145.     beq    resetsp
  146.  
  147.     moveq    #FILEBND,d3
  148.     move.l    a5,d2
  149.     add.l    d5,d3
  150.     jsr    _LVORead(a6)
  151.  
  152.     SETMSG    ld1
  153.     cmp.l    d0,d5
  154.     beq.s    repload
  155.     SETMSG    ld2
  156.     cmp.l    d0,d5
  157.     bgt.s    repload
  158.     SETMSG    ld3
  159.  
  160. repload    movea.l    d0,a2
  161.     bsr    stdout
  162.  
  163.     move.l    d4,d1
  164.     jsr    _LVOClose(a6)
  165.     cmp.l    a2,d5
  166.     bne    resetsp
  167.  
  168.  
  169. **********************************************************************
  170. **  CHECK FILE  ******************************************************
  171. **********************************************************************
  172.  
  173.  
  174.     moveq    #(4-1),d0
  175.     lea    $14ef(a5),a0
  176. getvers    asl.l    #BITSPERBYTE,d1
  177.     move.b    (a0)+,d1
  178.     dbf    d0,getvers
  179.  
  180.     SETMSG    ve1
  181.  
  182.     moveq    #DOSTRUE,d4
  183.     cmpi.l    #"1.83",d1
  184.     beq.s    repver
  185.  
  186.     moveq    #DOSFALSE,d4
  187.     SETMSG    ve2
  188.  
  189. repver    bsr.s    stdout
  190.     tst.l    d4
  191.     beq.s    resetsp
  192.  
  193.  
  194. **********************************************************************
  195. **  PATCH FILE  ******************************************************
  196. **********************************************************************
  197.  
  198.  
  199.     lea    patch(pc),a0
  200.     moveq    #((patche-patch)>>2)-1,d0
  201. chgbin    movem.w    (a0)+,d1-2
  202.     move.w    d2,0(a5,d1.w)
  203.     dbf    d0,chgbin
  204.  
  205. **********************************************************************
  206. **  SAVE FILE  *******************************************************
  207. **********************************************************************
  208.  
  209.  
  210.     move.l    sp,d1
  211.     move.l    #MODE_NEWFILE,d2
  212.     jsr    _LVOOpen(a6)
  213.  
  214.     SETMSG    sa1
  215.     move.l    d0,d4
  216.     bne.s    saving
  217.     SETMSG    sa2
  218.  
  219. saving    bsr.s    stdout
  220.  
  221.     move.l    d4,d1
  222.     beq.s    resetsp
  223.     move.l    a5,d2
  224.     move.l    d5,d3
  225.     jsr    _LVOWrite(a6)
  226.  
  227.     SETMSG    sv1
  228.     cmp.l    d0,d5
  229.     beq.s    repsave
  230.     SETMSG    sv2
  231.  
  232. repsave    movea.l    d0,a2
  233.     bsr.s    stdout
  234.  
  235.     move.l    d4,d1
  236.     jsr    _LVOClose(a6)
  237.     cmp.l    a2,d5
  238.     beq.s    resetsp
  239.  
  240.     move.l    sp,d1
  241.     jsr    _LVODeleteFile(a6)
  242.  
  243.  
  244. **********************************************************************
  245. **  END OF PROGRAM  **************************************************
  246. **********************************************************************
  247.  
  248.  
  249. resetsp    adda.l    #BUFSIZE,sp
  250.  
  251. clsdos    movea.l    a6,a1
  252.     movea.l    4.w,a6
  253.     jsr    _LVOCloseLibrary(a6)
  254.  
  255. fault    moveq    #RETURN_OK,d0
  256.     rts
  257.  
  258.  
  259. **********************************************************************
  260. **  bsr    stdout SUBROUTINE  *******************************************
  261. **********************************************************************
  262.  
  263.  
  264. stdout    move.l    d7,d1
  265.     move.l    a0,d2
  266.     jmp    _LVOWrite(a6)
  267.  
  268.  
  269. **********************************************************************
  270. **  PATCHES  *********************************************************
  271. **********************************************************************
  272.  
  273. STKSIZE    SET    STKSIZE & ~%11
  274.  
  275.     IFLE    STKSIZE-$20C
  276.     FAIL    AKAs array is too small
  277.     ENDC
  278.  
  279.     IFLT    (MININT>>16)-STKSIZE
  280.     FAIL    AKAs array is too big
  281.     ENDC
  282.  
  283.     CNOP    0,BYTESPERLONG
  284. patch    DC.W    $2972,-STKSIZE
  285.     DC.W    $2980,-STKSIZE
  286.     DC.W    $2992,-STKSIZE+BYTESPERLONG
  287.     DC.W    $29C0,-STKSIZE+BYTESPERLONG
  288.     DC.W    $29C8,-STKSIZE
  289. patche    ;    dummy
  290.  
  291.  
  292. **********************************************************************
  293. **  STRING CONSTANTS  ************************************************
  294. **********************************************************************
  295.  
  296.  
  297.     DC.B    "$","VER: TD183_EMSI/AKA_bugfix 33.01 (25.2.94)",EOS
  298.  
  299. dosname    DOSNAME
  300.  
  301.  
  302.  
  303. msginf    DC.B    "TrapDoor 1.83 EMSI-AKA bugfix",LF
  304.     DC.B    "by Nicola Soggia (2:331/315.3@Fidonet)",LF
  305.     DC.B    "",LF
  306.     DC.B    "WARNING! THE FILE WILL BE OVERWRITTEN, WORK ONLY ON BACKUP COPIES",LF
  307.     DC.B    "",LF
  308.     DC.B    "Enter filename: "
  309. msginfe    ;    dummy
  310.  
  311.  
  312.  
  313. msglo1    DC.B    "",LF
  314.     DC.B    "Reading file... "
  315. msglo1e    ;    dummy
  316.  
  317. msglo2    DC.B    "",LF
  318.     DC.B    "Can't read file",LF
  319. msglo2e    ;    dummy
  320.  
  321. msglo3    DC.B    "",LF
  322.     DC.B    "Aborted",LF
  323. msglo3e    ;    dummy
  324.  
  325.  
  326.  
  327. msgld1    DC.B    "ok",LF
  328. msgld1e    ;    dummy
  329.  
  330. msgld2    DC.B    "too short!",LF
  331. msgld2e    ;    dummy
  332.  
  333. msgld3    DC.B    "too long!",LF
  334. msgld3e    ;    dummy
  335.  
  336.  
  337.  
  338. msgve1    DC.B    "TD recognized and patched",LF
  339. msgve1e    ;    dummy
  340.  
  341. msgve2    DC.B    "Unknown TD version, sorry",LF
  342. msgve2e    ;    dummy
  343.  
  344.  
  345.  
  346. msgsa1    DC.B    "Writing file... "
  347. msgsa1e    ;    dummy
  348.  
  349. msgsa2    DC.B    "Can't write file",LF
  350. msgsa2e    ;    dummy
  351.  
  352. msgsv1    DC.B    "ok",LF
  353. msgsv1e    ;    dummy
  354.  
  355. msgsv2    DC.B    "error! (deleting file)",LF
  356. msgsv2e    ;    dummy
  357.  
  358.  
  359.  
  360. **********************************************************************
  361. **  TRPADOOR FILE BUFFER  ********************************************
  362. **********************************************************************
  363.  
  364.  
  365.     SECTION    BUFFER,BSS
  366.  
  367.  
  368. buffer    DS.B    TDSIZE+FILEBND
  369.  
  370.